#include "stdio.h"
#include "string.h"
#include "math.h"
#include "stdlib.h"
#include "collection.h"

double mysqrt(double a, double x0);
double fraction_sum(int n);
void reverse_array();

void main()
{
    /* 初始化单链表 */
    /* Link_List *list = (Link_List *) malloc(sizeof(Link_List)); */
    /* init_s_node_head(list); */

    /* for(int i = 1; i <= 20; i++) { */
        /* Stu *stu = (Stu *) malloc(sizeof(Stu)); */
        /* stu -> age = i; */
        /* insert_s_node_elem(list, i, stu); */
    /* } */

    /* int index = 21; */

    /* 测试单链表新增 */
    /* Stu *stu1 = (Stu *) malloc(sizeof(Stu)); */
    /* stu1->age = 34; */
    /* insert_s_node_elem(list, index, stu1); */

    /* 测试单链表删除 */
    /* Stu *stu1 = delete_s_node_elem(list, index); */
    /* if(stu1) printf("deleted age: %d\n\n", stu1->age); */
    /* else printf("delete failed: %d\n\n", index); */

    /* 测试单链表查询 */
    /* Stu *stu1 = get_s_node_elem(list, index); */
    /* if(stu1) printf("retrieved age: %d\n\n", stu1->age); */
    /* else printf("retrieved failed: %d\n\n", index); */

    /* 打印单链表 */
    /* for(int i = 0; i < list -> s_size; i++) { */
        /* Stu *stu = get_s_node_elem(list, i + 1); */
        /* printf("sq: %d, age: %d\n", i + 1, stu -> age); */
    /* } */




    /* 初始化顺序表 */
    Sq_List *list = (Sq_List *) malloc(sizeof(Sq_List));
    init_sq_list(list);
    for(int i = 1; i <= 10; i++) {
        Stu *stu = (Stu *) malloc(sizeof(Stu));
        stu->age = i * 2;
        insert_sq_list(list, i, stu);
    }

    Stu *stu1 = (Stu *) malloc(sizeof(Stu));
    stu1->age = 43;
    insert_sq_list(list, 5, stu1);

    for(int i = 0; i < list->size; i++) {
        printf("sq: %d, age: %d\n", i + 1, (list->arr + i)->age);
    }
    printf("Sq_List size: %d, list_size: %d\n", list->size, list->list_size);








    /* C语言测试 */
    /* int a[] = {0}; */
    /* char c[] = {'a','b','C'}; */
    /* char b[3] = {97,98,99,100}; */
    /* int d[10] = {}; */
    /* char e[] = "hello"; */
    /* puts(b); */
    /* printf("hello world!!!\n"); */
    /* printf("%d\n", -9%5); */
    /* char ss[10] = "12345"; */
    /* gets(ss); */
    /* printf("%s\n", ss); */
    /* char str[10 ]="ab\n2\\"; printf("%d,%d",strlen(str),sizeof(str)); */

    /* char str[] = "ab\n\012\\\""; */
    /* puts(str); */
    /* printf("%d", strlen(str)); */

    /* char a = '\012'; */
    /* printf("%c", a); */

    /* double x; */
    /* printf("Enter x:"); */
    /* scanf("%lf",&x); */
    /* printf("\nThe sqrt of %lf = %lf\n",x,mysqrt(x,x)); */

    /* 自然数倒数之和测试 */
    /* int n; */
    /* double s; */
    /* printf("\n"); */
    /* scanf("%d", &n); */
    /* s = fraction_sum(n); */
    /* printf("\n%.2f\n", s); */

    /* 数组反转测试 */
    /* printf("\n"); */
    /* reverse_array(); */
}

/* 计算平方根 */
double mysqrt(double a, double x0)
{
    double x1, y;
    x1=0.5*(x0+a/x0);
    if(fabs(x1-x0)>0.00001) y=mysqrt(a,x1);
    else y=x1;
    return y;
}

/* 计算n以内能被5和9整除的所有自然数的倒数之和 */
double fraction_sum(int n)
{
    int i;
    double m,sum = 0, s;
    for(int i = 1; i <=n; i++) {
        if(i % 5 == 0 || i % 9 == 0) {
            s = i;
            m = 1.0 / s;
            sum = sum + m;
        }
    }
    return sum;
}

/* 数组反转 */
void reverse_array()
{
    int n,t;
    scanf("%d", &n);
    int a[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n - i - 1; i++) {
        t = a[i];
        a[i] = a[n - i - 1];
        a[n - i - 1] = t;
    }
    for(int i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
}
